package model

import (
	jsoniter "github.com/json-iterator/go"
	"time"
)

type Department struct {
	ID              uint      `gorm:"primary_key"`
	CreatedAt       time.Time `json:"createdTime"`
	UpdatedAt       time.Time `json:"updatedTime"`
	Name            string    `json:"name" gorm:"NOT NULL;UNIQUE"`
	ManagerUserId   uint      `json:"managerUserId"`
	ManagerUserName string    `json:"managerUserName" gorm:"-;ForeignKey:DepartmentId"`
}

type CustomDepartment struct {
	ID   uint   `json:"id"`
	Name string `json:"name"`
	ManagerUserId   uint      `json:"managerUserId"`
	ManagerUserName string    `json:"managerUserName"`
}

type DepartmentCopy struct {
	Department
}

func (c *DepartmentCopy) MarshalJSON() ([]byte, error) {
	d := CustomDepartment {
		ID:   c.ID,
		Name: c.Name,
		ManagerUserId:c.ManagerUserId,
		ManagerUserName:c.ManagerUserName,
	}
	return jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(d)
}